package com.wee.fragment.find;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;



import com.bigtotoro.UILImageLoader;
import com.nostra13.universalimageloader.core.DisplayImageOptions;

import com.wee.aircoach_user.MyApplication;
import com.wee.aircoach_user.R;

import com.wee.entity.TrainDetails;

import java.util.List;

/**
 * Created by STS on 2016/4/7.
 */
public class StsAdapter extends BaseAdapter {

    private Context context;
    private List<TrainDetails.DataBean.ImageBean> data;
    private DisplayImageOptions options;
    public StsAdapter(Context context, List<TrainDetails.DataBean.ImageBean> data) {
        this.context = context;
        this.data = data;
        options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.find_nocoach)
                .showImageForEmptyUri(R.drawable.find_nocoach)
                .showImageOnFail(R.drawable.find_nocoach)
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .considerExifParams(true)
                        //.displayer(new RoundedBitmapDisplayer(Color.WHITE, 5))
                .build();
        UILImageLoader.initImageLoader(context.getApplicationContext());

    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder ;
        if(convertView==null) {
            holder = new ViewHolder();
            LayoutInflater inflate = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflate.inflate(R.layout.item_coach_imgs, null);

            holder.image= (ImageView) convertView.findViewById(R.id.image);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder)convertView.getTag();
        }
        TrainDetails.DataBean.ImageBean actions=data.get(position);

        String imgUrl = actions.getUrl();
        if(imgUrl!=null && imgUrl.length()!=0){
            com.android.volley.toolbox.ImageLoader.ImageListener imageListener = com.android.volley.toolbox.ImageLoader.getImageListener(holder.image, R.drawable.no_have_teacher, R.drawable.no_have_teacher);
            MyApplication.getInstance().getImageLoader().get(imgUrl, imageListener, 100, 100);
        }else{
            holder.image.setImageResource(R.drawable.no_have_teacher);
        }
        return convertView;
    }
    static class ViewHolder{

        ImageView image;
    }
}
